package com.mbbb.yygh.msm.service.impl;

import com.mbbb.yygh.msm.utils.HttpUtils;
import com.mbbb.yygh.msm.service.MsmService;
import com.mbbb.yygh.vo.msm.MsmVo;
import org.apache.http.HttpResponse;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class MsmServiceImpl implements MsmService {

    //发送mq消息短信
    //TODO 模拟短信发送
    @Override
    public void sendMq(MsmVo msmVo) {
        String phone = msmVo.getPhone();
        System.out.println("短信已发送至：" + phone);
    }

    //调用鼎信方法根据手机发送验证码
    @Override
    public boolean sendCode(String phone, String code) {
        String host = "http://dingxin.market.alicloudapi.com";
        String path = "/dx/sendSms";
        String method = "POST";
        String appcode = "938a8491cea74e43a48edf0a67070051";
        Map<String, String> headers = new HashMap<String, String>();
        //Authorization:APPCODE 83359fd73fe94948385f570e3c139105
        headers.put("Authorization", "APPCODE " + appcode);
        Map<String, String> querys = new HashMap<String, String>();
        querys.put("mobile", phone);
        querys.put("param", "code:"+code);
        querys.put("tpl_id", "TP1711063");
        Map<String, String> bodys = new HashMap<String, String>();
        try {
            HttpResponse response = HttpUtils.doPost(host, path, method, headers,
                    querys, bodys);
            System.out.println(response.toString());
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
